﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.Collections;

namespace MVCPets.Extensions
{
  public static class PrimativeExtensions
  {
    public static Nullable<T> AsNullable<T>(this T foo) where T : struct
    {
      return new Nullable<T>(foo);
    }

    public static string Concatinate<T>(this T foo, string arg0) where T : struct
    {
      return string.Concat(foo, arg0);
    }

    public static string Concatinate<T>(this T foo, string arg0, string arg1) where T : struct
    {
      return string.Concat(foo, arg0, arg1);
    }

    public static string Concatinate<T>(this T foo, params string[] args) where T : struct
    {
      StringBuilder sb = new StringBuilder(foo.ToString());
      foreach (string s in args)
      {
        sb.Append(s);
      }

      return sb.ToString();
    }

    public static string GetString(this byte[] value)
    {
      return System.Text.Encoding.ASCII.GetString(value);
    }

    public static string ToBase64String(this byte[] value)
    {
      return Convert.ToBase64String(value);
    }

    public static byte[] ComputeHash(this byte[] value)
    {
      var MD5 = new MD5CryptoServiceProvider();
      return MD5.ComputeHash(value);
    }    
  }
}
